<?php
namespace app\home\controller;

use think\Controller;
use think\Request;
use think\Loader;
use think\Db;

class Index extends Controller
{
    public function index()
    {
        $nav =  [
            ['url'=>'#page1','text'=>'首页'],
            ['url'=>'#page2','text'=>'服务'],
            ['url'=>'#page3','text'=>'案例'],
            ['url'=>'#page4','text'=>'客户'],
            ['url'=>'#page5','text'=>'特色'],
            ['url'=>'#page6','text'=>'增值'],
            ['url'=>'#page7','text'=>'关于'],
            ['url'=>'#page8','text'=>'联系'],
            ['url'=>'home/news/index','text'=>'资讯'],
        ];
        $this->assign('nav',$nav);
        //成功案例
        $data['cases'] = db('cases')->where(['is_open'=>1])->limit(3)->order('add_time desc')->select()?:[];
        //合作伙伴
        $data['partners'] = db('ad')->where(['adpos_id'=>9,'enabled'=>1])->limit(10)->order('')->select()?:[];
        //新闻
        $data['news'] = db('article')->limit(5)->order('add_time desc')->select();
        //公司行业
        $data['industry'] = db('cases_cat')->field('cat_name')->where(['parent_id'=>2])->select();
        //服务类型
        $data['service_type'] = db('cases_cat')->field('cat_name')->where(['parent_id'=>1])->select();
        return $this->fetch('',$data);
    }


    public function resume()
    {
        return $this->fetch();
    }

    public function add()
    {
        if(Request::instance()->isPost())
        {
            $validate = Loader::validate('Messages');
            $messages = input('post.');
            if($validate->check($messages))
            {
                $messages['add_time'] = time();
                $res = Db::name('messages')->insert($messages);
                if($res)
                {
                    echo json_encode('success');
                }
                else
                {
                    echo json_encode('fail');
                }
            }
            else
            {
                echo json_encode($validate->getError());
            }
        }
    }

    public function xx()
    {
        return $this->fetch();
    }

}
